package flag

import (
	"gvb_server/global"
	"gvb_server/models"
)

func Makemigrations() {
	global.Log.Infoln("【开始】初始化表")
	var err error
	global.DB.SetupJoinTable(&models.MenuModel{}, "Banners", &models.MenuBannerModel{})
	global.DB.SetupJoinTable(&models.UserModel{}, "CollectsModels", &models.UserCollectModel{})
	err = global.DB.Set("gorm:table_options", "ENGINE=InnoDB CHARSET=utf8mb4").AutoMigrate(
		&models.ArticleModel{},
		&models.BannerModel{},
		&models.MenuBannerModel{},
		&models.MenuModel{},
		&models.TagModel{},
		&models.UserModel{},
		&models.CommentModel{},
	)
	if err != nil {
		global.Log.Errorln("【失败】初始化表", err)
		return
	}
	global.Log.Infoln("【成功】初始化表")
}
